|
|
|
|
|
|
|
To provide smooth motion while preventing temporal aliasing and tearing, you should: |
|
|
|
|
|
|
|
|
Display at least 12 images per secondmore if possible |
|
|
|
|
|
|
|
|
Display images no faster than your monitor can handle them |
|
|
|
|
|
|
|
|
Whether or not you can achieve these goals, particularly the first one, depends on how you approach the problem. If you store your images as bitmaps in memory, you may be able to display them quickly enough. In fact, you may want to slow things down a bit to prevent temporal aliasing or to allow you to store fewer images for the same duration. For example, if you display 12 images per second even though your computer is fast enough to display 24, you would need to store only half as many images per second of animation. |
|
|
|
|
|
|
|
|
There are several approaches you can take to timing images in Visual Basic. The simplest is to present the images as quickly as possible. This approach works well in many situations, but it has its drawbacks. You may need to store more images than are really necessary. If each image takes a different amount of time to prepare and display, motion may appear irregular. This method also puts you at the mercy of the hardware running your application. The animation will look very different depending on the type of machine that is running it. This problem grows larger with each new generation of faster computers. |
|
|
|
|
|
|
|
|
Two more sophisticated methods for timing image display are using a timer control and clock watching. |
|
|
|
|
|
|
|
|
The easiest way to animate a series of bitmaps is to display them one after another in a loop. The following code shows one method for doing this. The program stores the frames in a hidden array of picture boxes named picFrame. It simply copies the images for each frame into the visible picCanvas control. The routine continues displaying images until it has shown them all or until the Boolean variable Playing is False. The DoEvents statement allows the operating system to perform other actions. In particular, it allows this program's Stop button to set Playing to False. |
|
|
|
 |
|
|
|
|
' Run the animation once or until Playing is False. Private Sub PlayImagesOnce()
Dim i As Integer
' Start the animation. For i = 0 To NumImages - 1
' Display the next frame. picCanvas.Picture = picFrame(i).Picture
DoEvents
NumPlayed = NumPlayed + 1 |
|
|
|
|
|